package thefirst.member.model;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import thefirst.support.model.HelpVO;
import thefirst.support.model.NoticeVO;
/**
 * TeacherOfMemberDaoImpl 
 * MemberDao를 implements한 클래스. 
 * 회원들이면 공통적으로 가지고 있는 메서드를
 * 선생님 회원에 맞게 overriding 을 진행.
 * 
 * sqlSessionTemplate을 활용해 Data access.
 * 
 * @author kosta-00-30
 * 
 */
@Repository
public class TeacherOfMemberDaoImpl implements MemberDao {
	@Resource(name = "sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;

	@Override
	public void registerMember(MemberVO mvo) throws SQLException {
		sqlSessionTemplate.insert("member.registerTeacher", mvo);
	}

	@Override
	public MemberVO showMember(MemberVO mvo) throws SQLException {
		return sqlSessionTemplate.selectOne("member.showTeacher", mvo);
	}

	@Override
	public int isExistId(MemberVO mvo) throws SQLException {
		System.out.println("dao" + mvo);
		int result = sqlSessionTemplate.selectOne("member.isExistTeaId", mvo);
		System.out.println("dao:" + result);
		return result;
	}

	/*
	 * @Override public int upload(TeacherVO tvo) throws SQLException{ return
	 * sqlSessionTemplate.insert("member.upload",tvo); }
	 */
	@Override
	public int updateName(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateTeacherName", mvo);
	}

	@Override
	public int updateGender(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateTeacherGender", mvo);
	}

	@Override
	public int updateTel(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateTeacherTel", mvo);
	}

	@Override
	public int updateEmail(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateTeacherEmail", mvo);
	}

	@Override
	public int updateHoperegion(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateTeacherHoperegion", mvo);
	}

	public int updateHopesubject(TeacherVO tvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate
				.update("member.updateTeacherHopesubject", tvo);
	}

	public int updateHopegender(TeacherVO tvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateTeacherHopegender", tvo);
	}

	public int updateAvailablestudent(TeacherVO tvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update(
				"member.updateTeacherAvailablestudent", tvo);
	}

	public int updateAvailableday(TeacherVO tvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateTeacherAvailableday",
				tvo);
	}

	public int updateAvailabletime(TeacherVO tvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateTeacherAvailabletime",
				tvo);
	}

	public int updateIntro(TeacherVO tvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateTeacherIntro", tvo);
	}

	public int updateUniversity(TeacherVO tvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateTeacherUniversity", tvo);
	}
	
	public int updatePicture(TeacherVO tvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("member.updateTeacherPicture", tvo);
	}
	
	@Override
	public MemberVO login(MemberVO mvo) throws SQLException {
		return sqlSessionTemplate.selectOne("member.loginteacher", mvo);
	}

	/**
	 * 페이징 처리를 위하여 선생님회원의 수를 가져온다.
	 */
	@Override
	public int selectTotalMemberCount() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * 페이징 처리를 위하여 선생님회원의 해당페이지 리스트를 가져온다.
	 */
	public List<?> getTeacherListBasic(String pageNo) throws SQLException {
		return sqlSessionTemplate.selectList("member.getTeacherListBasic",
				pageNo);
	}

	@Override
	public void withdrawalMember(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		sqlSessionTemplate.update("member.withdrawalTeacher", mvo);

	}

	/**
	 * mvo로 들어온 값(name,email)으로 선생님의 id를 가져온다.
	 */
	@Override
	public String findIdByNameEmail(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectOne("member.findTeacherIdByNameEmail",
				mvo);
	}

	@Override
	public List<?> getListForAdmin(String pageNo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public MemberVO findQPassByIdEmail(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectOne("member.findTeacherQPassByIdEmail",
				mvo);
	}

	@Override
	public String findPasswordByQnAPass(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectOne(
				"member.findTeacherPasswordByQnAPass", mvo);
	}

	/**
	 * 페이징빈에 처리하기위한 전체 선생님리스트를 region(희망지역) 순으로 검색
	 * 
	 * @param memberSearchVO
	 * @return
	 * @throws SQLException
	 */
	public List<?> getTeacherListRegion(MemberSearchVO memberSearchVO)
			throws SQLException {
		return sqlSessionTemplate.selectList("member.getTeacherListRegion",
				memberSearchVO);
	}

	/**
	 * 페이징빈에 처리하기위한 전체 선생님리스트를 hopesubject(희망과목) 순으로 검색
	 * 
	 * @param memberSearchVO
	 * @return
	 * @throws SQLException
	 */
	public List<?> getTeacherListSubject(MemberSearchVO memberSearchVO)
			throws SQLException {
		return sqlSessionTemplate.selectList("member.getTeacherListSubject",
				memberSearchVO);
	}
	/**
	 * 페이징빈에 처리하기위한 선생님리스트를  university(출신대학),
	 * 이름이 동일한 자료를 검색(이름은 없을 수도 있다.)
	 * @param memberSearchVO
	 * @return
	 * @throws SQLException
	 */
	public List<?> getListTeacherbyUniversity(MemberSearchVO memberSearchVO) throws SQLException{
		return sqlSessionTemplate.selectList("member.getListTeacherbyUniversity", memberSearchVO);
	}
	/**
	 * 페이징빈에 처리하기위한 전체 선생님리스트를 university(출신대학별) 순으로 검색
	 * 
	 * @param memberSearchVO
	 * @return
	 * @throws SQLException
	 */
	public List<?> getTeacherListUniversity(MemberSearchVO memberSearchVO)
			throws SQLException {
		return sqlSessionTemplate.selectList("member.getTeacherListUniversity",
				memberSearchVO);
	}
	/**
	 * 선생님찾기-전체보기-검색조건에 맞는 데이타를 처리	
	 * @param memberSearchVO
	 * @return
	 */
	public List<?> getListTeacherbyTotal(MemberSearchVO memberSearchVO) {
		return sqlSessionTemplate.selectList("member.getListTeacherbyTotal", memberSearchVO);
	}
	/**
	 * 페이징빈에 처리하기위한 학생리스트를 region(희망과외지역) 자료를 검색
	 * 
	 * @param memberSearchVO
	 * @return
	 * @throws SQLException
	 */
	public List<?> getListTeacherbyRegion(MemberSearchVO memberSearchVO)
			throws SQLException {
		return sqlSessionTemplate.selectList("member.getListTeacherbyRegion",
				memberSearchVO);
	}

	/**
	 * 페이징빈에 처리하기위한 학생리스트를 region(희망과외지역), 이름이 동일한 자료를 검색
	 * 
	 * @param memberSearchVO
	 * @return
	 * @throws SQLException
	 */
	public List<?> getListTeacherbyRegionAndName(MemberSearchVO memberSearchVO)
			throws SQLException {
		return sqlSessionTemplate.selectList(
				"member.getListTeacherbyRegionAndName", memberSearchVO);
	}

	/**
	 * 페이징빈에 처리하기위한 학생리스트를 subject(희망과외과목) 자료를 검색
	 * 
	 * @param memberSearchVO
	 * @return
	 * @throws SQLException
	 */
	public List<?> getListTeacherbySubject(MemberSearchVO memberSearchVO)
			throws SQLException {
		return sqlSessionTemplate.selectList("member.getListTeacherbySubject",
				memberSearchVO);
	}

	/**
	 * 페이징빈에 처리하기위한 학생리스트를 subject(희망과외과목), 이름이 동일한 자료를 검색
	 * 
	 * @param memberSearchVO
	 * @return
	 * @throws SQLException
	 */
	public List<?> getListTeacherbySubjectAndName(MemberSearchVO memberSearchVO)
			throws SQLException {
		return sqlSessionTemplate.selectList(
				"member.getListTeacherbySubjectAndName", memberSearchVO);
	}

	/**
	 * 선생님찾기- 출신대학별에서 대학명에 대한 autocomplete을 처리하는 메서드
	 * 
	 * @param term
	 * @return
	 */
	public List<String> getUniversityName(String term) throws SQLException {
		System.out.println(sqlSessionTemplate.selectList(
				"member.getUniversityName", term));
		return sqlSessionTemplate.selectList("member.getUniversityName", term);
	}

	@Override
	public List<MyHelpVO> getMyHelpList(MyHelpVO myHelpVO) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectList("member.myHelpTeacherList",
				myHelpVO);
	}
	/**
	 * 관리자 페이지 선생님 리스트 가져오기
	 * @param pageNo
	 * @return
	 * @throws SQLException
	 */
	public List<TeacherVO> getTeacherListOrderByName(String pageNo) throws SQLException{
		return sqlSessionTemplate.selectList("member.getTeacherListOrderByName",pageNo);
	}
	/**
	 * 관리자 페이지 선생님 리스트 가져오기(가입일순)
	 * @param pageNo
	 * @return
	 * @throws SQLException
	 */
	public List<TeacherVO> getTeacherListOrderByDate(String pageNo) throws SQLException{
		return sqlSessionTemplate.selectList("member.getTeacherListOrderByDate",pageNo);
	}
	
	/**
	 * 선생님 총 인원수
	 * @return
	 * @throws SQLException
	 */
	public int totalTeacherContent() throws SQLException{
		return sqlSessionTemplate.selectOne("member.totalTeacherContent");
	}

	/**
	 * 선생님 Id를 받아서 선생님 정보를 리턴해준다.
	 * @param tvo
	 * @return
	 */
	public TeacherVO getTeacherInfobyId(TeacherVO tvo) throws SQLException{
		return sqlSessionTemplate.selectOne("member.getTeacherInfobyId",tvo);	
	}
	public int totalTeacherContetnBySubject(MemberSearchVO memberSearchVO) throws SQLException{
		return sqlSessionTemplate.selectOne("member.totalTeacherContetnBySubject",memberSearchVO);
	}
	public int totalTeacherContetnByUniversity(MemberSearchVO memberSearchVO) throws SQLException{
		return sqlSessionTemplate.selectOne("member.totalTeacherContetnByUniversity",memberSearchVO);
	}
	public int totalTeacherContetnByRegion(MemberSearchVO memberSearchVO) throws SQLException{
		return sqlSessionTemplate.selectOne("member.totalTeacherContetnByRegion",memberSearchVO);
	}
	
	public List<TeacherVO> getTeacherListForLeft() throws SQLException{
		return sqlSessionTemplate.selectList("member.getTeacherListForLeft");
	}
}
